from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-05 14:02:41.478304
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 05, Nov, 2022
Time: 14:02:51
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.8721
Nobs: 831.000 HQIC: -51.1874
Log likelihood: 10827.6 FPE: 4.83510e-23
AIC: -51.3836 Det(Omega_mle): 4.34161e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297782 0.051080 5.830 0.000
L1.Burgenland 0.109379 0.034987 3.126 0.002
L1.Kärnten -0.106426 0.018634 -5.711 0.000
L1.Niederösterreich 0.210405 0.073184 2.875 0.004
L1.Oberösterreich 0.100549 0.069691 1.443 0.149
L1.Salzburg 0.251200 0.037117 6.768 0.000
L1.Steiermark 0.035772 0.048722 0.734 0.463
L1.Tirol 0.106945 0.039443 2.711 0.007
L1.Vorarlberg -0.059059 0.034009 -1.737 0.082
L1.Wien 0.057780 0.062480 0.925 0.355
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.069035 0.105460 0.655 0.513
L1.Burgenland -0.031607 0.072235 -0.438 0.662
L1.Kärnten 0.047380 0.038471 1.232 0.218
L1.Niederösterreich -0.172241 0.151094 -1.140 0.254
L1.Oberösterreich 0.377603 0.143883 2.624 0.009
L1.Salzburg 0.288790 0.076631 3.769 0.000
L1.Steiermark 0.105793 0.100590 1.052 0.293
L1.Tirol 0.315902 0.081433 3.879 0.000
L1.Vorarlberg 0.023459 0.070214 0.334 0.738
L1.Wien -0.017496 0.128994 -0.136 0.892
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195155 0.026396 7.393 0.000
L1.Burgenland 0.092102 0.018080 5.094 0.000
L1.Kärnten -0.008808 0.009629 -0.915 0.360
L1.Niederösterreich 0.266380 0.037818 7.044 0.000
L1.Oberösterreich 0.116193 0.036013 3.226 0.001
L1.Salzburg 0.051963 0.019180 2.709 0.007
L1.Steiermark 0.017084 0.025177 0.679 0.497
L1.Tirol 0.097456 0.020382 4.781 0.000
L1.Vorarlberg 0.057307 0.017574 3.261 0.001
L1.Wien 0.116193 0.032287 3.599 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105873 0.027039 3.916 0.000
L1.Burgenland 0.046605 0.018520 2.516 0.012
L1.Kärnten -0.017146 0.009863 -1.738 0.082
L1.Niederösterreich 0.196238 0.038739 5.066 0.000
L1.Oberösterreich 0.282038 0.036890 7.645 0.000
L1.Salzburg 0.119931 0.019647 6.104 0.000
L1.Steiermark 0.101979 0.025790 3.954 0.000
L1.Tirol 0.121910 0.020879 5.839 0.000
L1.Vorarlberg 0.069813 0.018002 3.878 0.000
L1.Wien -0.027935 0.033072 -0.845 0.398
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128471 0.049101 2.616 0.009
L1.Burgenland -0.049564 0.033632 -1.474 0.141
L1.Kärnten -0.039894 0.017912 -2.227 0.026
L1.Niederösterreich 0.166076 0.070348 2.361 0.018
L1.Oberösterreich 0.139092 0.066991 2.076 0.038
L1.Salzburg 0.285053 0.035679 7.989 0.000
L1.Steiermark 0.033488 0.046834 0.715 0.475
L1.Tirol 0.164147 0.037915 4.329 0.000
L1.Vorarlberg 0.104745 0.032691 3.204 0.001
L1.Wien 0.070108 0.060059 1.167 0.243
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060954 0.038831 1.570 0.116
L1.Burgenland 0.041531 0.026597 1.561 0.118
L1.Kärnten 0.049693 0.014165 3.508 0.000
L1.Niederösterreich 0.227661 0.055633 4.092 0.000
L1.Oberösterreich 0.271687 0.052978 5.128 0.000
L1.Salzburg 0.057878 0.028216 2.051 0.040
L1.Steiermark -0.008303 0.037037 -0.224 0.823
L1.Tirol 0.155617 0.029984 5.190 0.000
L1.Vorarlberg 0.068969 0.025853 2.668 0.008
L1.Wien 0.075062 0.047496 1.580 0.114
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180317 0.046516 3.876 0.000
L1.Burgenland -0.004754 0.031861 -0.149 0.881
L1.Kärnten -0.060903 0.016969 -3.589 0.000
L1.Niederösterreich -0.085598 0.066645 -1.284 0.199
L1.Oberösterreich 0.191676 0.063464 3.020 0.003
L1.Salzburg 0.058839 0.033801 1.741 0.082
L1.Steiermark 0.228085 0.044368 5.141 0.000
L1.Tirol 0.493884 0.035919 13.750 0.000
L1.Vorarlberg 0.049184 0.030970 1.588 0.112
L1.Wien -0.048845 0.056897 -0.858 0.391
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.156083 0.052993 2.945 0.003
L1.Burgenland -0.009687 0.036297 -0.267 0.790
L1.Kärnten 0.065067 0.019331 3.366 0.001
L1.Niederösterreich 0.201846 0.075923 2.659 0.008
L1.Oberösterreich -0.068540 0.072300 -0.948 0.343
L1.Salzburg 0.221848 0.038506 5.761 0.000
L1.Steiermark 0.115125 0.050546 2.278 0.023
L1.Tirol 0.082242 0.040920 2.010 0.044
L1.Vorarlberg 0.123917 0.035282 3.512 0.000
L1.Wien 0.113694 0.064819 1.754 0.079
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353117 0.031025 11.382 0.000
L1.Burgenland 0.007846 0.021251 0.369 0.712
L1.Kärnten -0.024387 0.011318 -2.155 0.031
L1.Niederösterreich 0.227115 0.044451 5.109 0.000
L1.Oberösterreich 0.163117 0.042329 3.854 0.000
L1.Salzburg 0.052024 0.022544 2.308 0.021
L1.Steiermark -0.016011 0.029593 -0.541 0.588
L1.Tirol 0.113950 0.023957 4.756 0.000
L1.Vorarlberg 0.072849 0.020657 3.527 0.000
L1.Wien 0.051442 0.037949 1.356 0.175
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043213 0.158473 0.191402 0.165220 0.129804 0.122537 0.068767 0.229659
Kärnten 0.043213 1.000000 0.001290 0.131764 0.044646 0.098694 0.428195 -0.051074 0.102549
Niederösterreich 0.158473 0.001290 1.000000 0.343961 0.165035 0.310109 0.124124 0.189709 0.336966
Oberösterreich 0.191402 0.131764 0.343961 1.000000 0.235210 0.338916 0.177299 0.178844 0.270719
Salzburg 0.165220 0.044646 0.165035 0.235210 1.000000 0.153172 0.143519 0.152541 0.140371
Steiermark 0.129804 0.098694 0.310109 0.338916 0.153172 1.000000 0.162061 0.147106 0.089464
Tirol 0.122537 0.428195 0.124124 0.177299 0.143519 0.162061 1.000000 0.120383 0.161863
Vorarlberg 0.068767 -0.051074 0.189709 0.178844 0.152541 0.147106 0.120383 1.000000 0.013908
Wien 0.229659 0.102549 0.336966 0.270719 0.140371 0.089464 0.161863 0.013908 1.000000